/**
 * Copyright (c) 2024 Huawei Technologies Co., Ltd
 * [graph-engine] is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
*/


#ifndef PARSER_TESTS_DEPENDS_MMPA_SRC_MMAP_STUB_H_
#define PARSER_TESTS_DEPENDS_MMPA_SRC_MMAP_STUB_H_

#include "mmpa/mmpa_api.h"
#include <memory>

#include <iostream>

namespace ge {
class MmpaStubApi {
 public:
  MmpaStubApi() = default;
  virtual ~MmpaStubApi() = default;

  virtual INT32 mmDladdr(VOID *addr, mmDlInfo *info)
  {
    return 0;
  }

  virtual VOID *mmDlopen(const CHAR *fileName, INT32 mode)
  {
    return NULL;
  }

  virtual INT32 mmRealPath(const CHAR *path, CHAR *realPath, INT32 realPathLen)
  {
    return 0;
  }
};

class MmpaStub {
 public:
  static MmpaStub& GetInstance() {
    static MmpaStub mmpa_stub;
    return mmpa_stub;
  }

  void SetImpl(const std::shared_ptr<MmpaStubApi> &impl) {
    impl_ = impl;
  }

  MmpaStubApi* GetImpl() {
    return impl_.get();
  }

  void Reset() {
    impl_ = std::make_shared<MmpaStubApi>();
  }

 private:
  MmpaStub(): impl_(std::make_shared<MmpaStubApi>()){}
  std::shared_ptr<MmpaStubApi> impl_;
};

}  // namespace parser
#endif // PARSER_TESTS_DEPENDS_MMPA_SRC_MMAP_STUB_H_
